<?php
$DIR_APPLICATION = $_SERVER['DOCUMENT_ROOT']."/opstocks/";
$HTTP_SERVER = "http://".$_SERVER['HTTP_HOST']."/opstocks/";

define('WEB_HOME', 'stocks/sector');

// HTTP
define('HTTP_SERVER', $HTTP_SERVER);
define('HTTP_CATALOG', $HTTP_SERVER);
define('HTTP_IMAGE', $HTTP_SERVER.'image/');

// HTTPS
define('HTTPS_SERVER', $HTTP_SERVER);
define('HTTPS_IMAGE', $HTTP_SERVER.'image/');

// DIR
define('DIR_APPLICATION', $DIR_APPLICATION);
define('DIR_SYSTEM', DIR_APPLICATION.'system/');
define('DIR_DATABASE', DIR_APPLICATION.'system/database/');
define('DIR_LANGUAGE', DIR_APPLICATION.'language/');
define('DIR_TEMPLATE', DIR_APPLICATION.'view/template/');
define('DIR_CONFIG', DIR_APPLICATION.'system/config/');
define('DIR_IMAGE', DIR_APPLICATION.'image/');
define('DIR_CACHE', DIR_APPLICATION.'system/cache/');
define('DIR_DOWNLOAD', DIR_APPLICATION.'download/');
define('DIR_LOGS', DIR_APPLICATION.'system/logs/');
define('DIR_CATALOG', DIR_APPLICATION.'catalog/');

// DB
define('DB_DRIVER', 'mysql');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'opstocks');
define('DB_PREFIX', '');


// Your custom class dir
define('CLASS_DIR', 'system/');

// Add your class dir to include path
set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR);

// You can use this trick to make autoloader look for commonly used "My.class.php" type filenames
spl_autoload_extensions('.php');

// Use default autoload implementation
//spl_autoload_register();
//require_once('classes/controller.php');

class ClassAutoloader {
    
    public function __construct() {
        spl_autoload_register(array($this, 'loader'));
    }
    
    private function loader($className) {

//    	echo 'Trying to load ', $className, ' via ', __METHOD__, "()\n";
    	
    	$file_name = CLASS_DIR.strtolower($className) . '.php';
    	    	
        if(is_file($file_name))
        	include $file_name;
    }
}

$autoloader = new ClassAutoloader();
?>
